<% layout('/layouts/default.html', {title: '备品备件入库管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text(componentPurchaseInfo.isNewRecord ? '备品备件入库' : '备品备件入库')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${componentPurchaseInfo}" action="${ctx}/test/componentPurchaseInfo/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="purchaseInfoCode"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('备品备件采购申请编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="purchaseApplyCode" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="" hidden="hidden">
								<span class="required hide">*</span> ${text('备品备件编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input:hidden path="componentCode" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('实际采购费用')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="purchaseCost" class="form-control digits"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="" hidden="hidden">
								<span class="required hide">*</span> ${text('备品备件采购数量')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input:hidden path="purchaseNumber" maxlength="11" class="form-control digits"/>
							</div>
						</div>
					</div>

				</div>
				<div class="row">
					<div class="col-xs-6">

						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('备品备件采购时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="purchaseDate" readonly="true" maxlength="20" class="form-control Wdate"
								dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="" hidden="hidden">
								<span class="required hide">*</span> ${text('备品备件生产厂商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input:hidden path="manufacture" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>

				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
			    <#form:input:hidden  path="extend.extendS2" maxlength="500" class="form-control"/>


				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${componentPurchaseInfo.id}" bizType="componentPurchaseInfo_file"
									uploadType="all" class="" readonly="false"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('备品备件采购信息')}</h4>
				<div class="ml10 mr10">
					<table id="componentPurchaseInfoChildDataGrid"></table>
					<% if (hasPermi('test:componentPurchaseInfo:edit')){ %>
						<a href="#" id="componentPurchaseInfoChildDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('test:componentPurchaseInfo:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化component_purchase_info_childDataGrid对象
$("#componentPurchaseInfoChildDataGrid").dataGrid({

	data: ${toJson(componentPurchaseInfo.componentPurchaseInfoChildList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'id', editable:true, hidden:true},
		{header:'${text('备品备件采购信息编号')}', name:'purchaseInfoCode.purchaseInfoCode', editable:true, hidden:true},
		{header:'${text('备品备件采购申请编号')}', name:'purchaseApplyCode', width:150,hidden:true, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
		//{header:'${text('purchase_sort')}', name:'purchaseSort', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control digits'}},
		{header:'${text('备品备件编号')}', name:'componentCode', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
		{header:'${text('备品备件采购数量')}', name:'purchaseNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control digits'}},
		{header:'${text('备品备件采购费用')}', name:'purchaseCost', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits'}},
		//{header:'${text('备品备件生产厂商')}', name:'manufacture', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control'}},
		//{header:'${text('备品备件采购时间')}', name:'purchaseDate', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
		{header:'${text('备注信息')}', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'500', 'class':'form-control', 'rows':'1'}},
		// {header:'${text('扩展 String 1')}', name:'extend.extendS1', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'11', 'class':'form-control digits'}},
		// {header:'${text('扩展 String 2')}', name:'extend.extendS2', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 String 3')}', name:'extend.extendS3', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 String 4')}', name:'extend.extendS4', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 String 5')}', name:'extend.extendS5', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 String 6')}', name:'extend.extendS6', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 String 7')}', name:'extend.extendS7', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 String 8')}', name:'extend.extendS8', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'500', 'class':'form-control'}},
		// {header:'${text('扩展 Integer 1')}', name:'extend.extendI1', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits'}},
		// {header:'${text('扩展 Integer 2')}', name:'extend.extendI2', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits'}},
		// {header:'${text('扩展 Integer 3')}', name:'extend.extendI3', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits'}},
		// {header:'${text('扩展 Integer 4')}', name:'extend.extendI4', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control digits'}},
		// {header:'${text('扩展 Float 1')}', name:'extend.extendF1', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		// {header:'${text('扩展 Float 2')}', name:'extend.extendF2', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		// {header:'${text('扩展 Float 3')}', name:'extend.extendF3', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		// {header:'${text('扩展 Float 4')}', name:'extend.extendF4', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		// {header:'${text('扩展 Date 1')}', name:'extend.extendD1', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
		// {header:'${text('扩展 Date 2')}', name:'extend.extendD2', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
		// {header:'${text('扩展 Date 3')}', name:'extend.extendD3', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
		// {header:'${text('扩展 Date 4')}', name:'extend.extendD4', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
		{header:'${text('操作')}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
				actions.push('<a href="#" onclick="js.confirm(\'${text('你确认要删除这条数据吗？')}\', function(){$(\'#componentPurchaseInfoChildDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}else{
				actions.push('<a href="#" onclick="js.confirm(\'${text('你确认要删除这条数据吗？')}\', function(){$(\'#componentPurchaseInfoChildDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'})});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#componentPurchaseInfoChildDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'componentPurchaseInfoChildList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,id,purchaseInfoCode.purchaseInfoCode,purchaseApplyCode,purchaseSort,componentCode,purchaseNumber,purchaseCost,manufacture,purchaseDate,createBy,createDate,updateBy,updateDate,remarks,extend.extendS1,extend.extendS2,extend.extendS3,extend.extendS4,extend.extendS5,extend.extendS6,extend.extendS7,extend.extendS8,extend.extendI1,extend.extendI2,extend.extendI3,extend.extendI4,extend.extendF1,extend.extendF2,extend.extendF3,extend.extendF4,extend.extendD1,extend.extendD2,extend.extendD3,extend.extendD4,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});


//获取url参数
(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]); return null;
    }
})(jQuery);

//入库自动获取申请编号
$(function () {
    if($.getUrlParam("opera")=="addcomponent"){

         $('#purchaseApplyCode').text($.getUrlParam("opera"));
	}

})
</script>